package com.dongdongshop.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.HttpResponseEnum;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.content.TbContent;
import com.dongdongshop.service.ContentServiceI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("contentController")
public class ContentController {

    private final Logger logger= LoggerFactory.getLogger(ContentController.class);

    @Reference
    private ContentServiceI contentServiceI;

    //轮播图
    @RequestMapping("getCarousel")
    @ResponseBody
    public Result<List<TbContent>> getCarousel(){
        try {
            List<TbContent> list=contentServiceI.getCarousel();
            for (TbContent content : list) {
                System.out.println("轮播图"+content);
            }
            return Result.jsonResponse(HttpResponseEnum.OK).setData(list);
        }catch (Exception e){
            logger.error("系统错误", e);
            return Result.jsonResponse(HttpResponseEnum.FAIL);
        }
    }
    //今日推荐
    @RequestMapping("getRecommend")
    @ResponseBody
    public Result findRecommendAll(){
        try {
            List<TbContent> list=contentServiceI.findRecommendAll();
            logger.info("查询方法");
            return Result.jsonResponse(HttpResponseEnum.OK).setData(list);
        }catch (Exception e){
            logger.info("数据查询失败",e);
            return Result.jsonResponse(HttpResponseEnum.FAIL);
        }
    }
    //猜喜欢
    @RequestMapping("getLike")
    @ResponseBody
    public Result findLikeAll(){
        try {
            List<TbContent> list=contentServiceI.findLikeAll();
            logger.info("查询方法");
            return Result.jsonResponse(HttpResponseEnum.OK).setData(list);
        }catch (Exception e){
            logger.info("数据查询失败",e);
            return Result.jsonResponse(HttpResponseEnum.FAIL);
        }
    }
    //有趣
    @RequestMapping("getAmusing")
    @ResponseBody
    public Result findAmusingAll(){
        try {
            List<TbContent> list=contentServiceI.findAmusingAll();
            logger.info("查询方法");
            return Result.jsonResponse(HttpResponseEnum.OK).setData(list);
        }catch (Exception e){
            logger.info("数据查询失败",e);
            return Result.jsonResponse(HttpResponseEnum.FAIL);
        }
    }
}
